﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UMLTouch.Core.Entities;
using System.Collections;

namespace UMLTouch.Domain.ClassDiagram.Patterns
{
    public class InheritanceArrow : IShapePattern
    {
        #region IShapePattern Members

        public ShapePatternMatchingResultEnum Match(Shape shape)
        {

            Shape shapeToAnalyse = shape;
            switch (shape.ShapeOpenType)
            {
                case ShapeOpenTypeEnum.Closed:
                    break;
                case ShapeOpenTypeEnum.Opened:

                    return ShapePatternMatchingResultEnum.MightMatch;
                case ShapeOpenTypeEnum.SemiClosed:
                    shapeToAnalyse = shape.SubShape;
                    break;
            }

            if (shapeToAnalyse.NbSegments < 4)
            {
                return ShapePatternMatchingResultEnum.MightMatch;
            }
            else if(shapeToAnalyse.NbSegments == 4
                && shapeToAnalyse.NbExtremityIntersections == 3
                && shapeToAnalyse.NbMiddleIntersections <= 1)
            {
                return ShapePatternMatchingResultEnum.Match;
            }


            return ShapePatternMatchingResultEnum.DontMatch; 

               
        }



        public override string ToString()
        {
            return "Inheritance arrow shape";
        }
        #endregion

        #region IShapePattern Members

        public System.Windows.Controls.Control CreateControl()
        {
            return new EntityControl();
        }

        #endregion
    }
}
